export const captchaCheck = (captcha) => {
  return new Promise((resolve, reject) => {
      if(!captcha) {
        reject({message: '验证码不能为空!'});
      }
      if(!/^\d{6}$/.test(captcha)) {
        reject({message: '验证码错误'});
      }
      resolve()
  })
}

export const phoneCheck = (phone) => {
  return new Promise((resolve, reject) => {
    if(!phone) {
      reject({message: '手机号不能为空!'});
    }
    if(!/^1[34578]\d{9}$/.test(phone)) {
      reject({message: '手机号错误!'});
    }
    resolve()
  })
}

export const loginCheck = (username, password) => {
  return new Promise((resolve, reject) => {
    if(!username) {
      reject({message: '账号不能为空!'})
      return
    }
    if(!/^1[34578]\d{9}$/.test(username) && !/.+@.+\..+/.test(username)) {
      reject({message: '账号错误!'})
      return
    }
    if(!password) {
      reject({message: '密码不能为空!'})
      return
    }
    resolve()
  })
}

export const passwordCheck = (password) => {
  return new Promise((resolve, reject) => {
    if(!password) {
      reject({message: '密码不能为空!'})
      return
    }
    if(!/^\d{6,16}$/.test(password)) {
      reject({message: '密码必须为6-16个字符!'})
    }
    resolve()
  })
}
